package com.podigua.example.nonmodular;

import com.alibaba.fastjson.JSON;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

import java.util.*;


/**
 * 应用实例
 *
 * @author podigua
 * @date 2024/03/04
 */
public class NonModularExampleApplication extends Application {


    @Override
    public void start(Stage stage) throws Exception {
        List<String> raws = getParameters().getRaw();
        HBox root = new HBox();
        TextArea text = new TextArea();
        StringJoiner joiner = new StringJoiner(System.lineSeparator());
        Properties properties = System.getProperties();
        if(raws!=null && !raws.isEmpty()){
            joiner.add("参数信息:");
            for (int index = 0; index < raws.size(); index++) {
                joiner.add("参数" + (index+1) + ":" + raws.get(index));
            }
            joiner.add("\n");
        }
        joiner.add("JSON信息:");
        Map<String, String> json = new HashMap<>();
        json.put("JSON","fast");
        joiner.add(JSON.toJSONString(json));
        joiner.add("\n内存信息:");
        long maxMemory = Runtime.getRuntime().maxMemory();
        joiner.add("max-memory:" + maxMemory);
        joiner.add("\n环境变量:");
        properties.forEach((k, v) -> {
            joiner.add(k + " : " + v);
        });
        text.setText(joiner.toString());
        text.prefWidthProperty().bind(root.widthProperty());
        text.prefHeightProperty().bind(root.heightProperty());
        root.getChildren().add(text);
        stage.setScene(new Scene(root, 800, 600));
        stage.setTitle("非模块化");
        stage.show();
    }
}
